package ${cfg.baseTestPackage};


import ${cfg.baseMapperPackage}.${table.beanName}DAO;
import ${cfg.baseDbBeanPackage}.domain.${table.beanName};
import ${cfg.baseServicePackage}.${table.beanName}Service;

import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.mryt.dt.base.Page;
import com.mryt.dt.base.PageReq;
import com.mryt.supplier.center.domain.Result;

import javax.annotation.Resource;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml", "classpath:META-INF/spring/provider.xml"})
@Slf4j
public class ${table.beanName}ServiceImplTest {

    @Autowired
    private ${table.beanName}DAO dao;

    @Autowired
    private ${table.beanName}Service service;


    @Test
    //@Transactional
    //@Rollback
    public void testAll(){
        save();
        enable();
        getById();
        findAll();
        page();
    }


    public void save() {

        boolean sucess = true;
        for(int i = 5; i<10;i++){
            ${table.beanName} entity = new ${table.beanName}();
            <#list table.propertyList as col>
                <#if col.propertyType == "String">
                    entity.set${col.propertyName?cap_first}("");
                <#elseif col.propertyType == "Integer">
                    entity.set${col.propertyName?cap_first}(0);
                <#elseif col.propertyName == "Long">
                   entity.set${col.propertyName?cap_first}(0L);
                <#else>
                    entity.set${col.propertyName?cap_first}();
                </#if>
            </#list>
            ApiResult result = service.save(entity);
            if(!result.isSuccess()){
                sucess =false;
                break;
            }
        }
        Assert.assertTrue(sucess);
    }


    public void enable() {

        ApiResult result = service.enable(1, 0);
        System.out.println(result);
        Assert.assertTrue(result.isSuccess());
    }



    public void getById() {
        ${table.beanName} entity = service.getById(1);
        Assert.assertTrue(entity !=null);
    }




    public void findAll() {

        List<${table.beanName}> list = service.findAll();
        System.out.println(list);
        Assert.assertTrue(list.size()>0);
    }


    @Test
    public void page() {
        PageReq<${table.beanName}> req = new PageReq<>();
        req.setPageNo(1);
        req.setPageSize(2);
        Page<${table.beanName}> page = service.page(req);
        System.out.println(page);
        Assert.assertTrue(page.getTotal()>0);
    }


}
